package com.qingke.easyjava.jdbc.app;

import com.qingke.easyjava.jdbc.command.CommandFactory;
import com.qingke.easyjava.jdbc.command.Command;
import com.qingke.easyjava.jdbc.command.CommandFactory.CommandCode;
import com.qingke.easyjava.jdbc.pojo.Player;
import com.qingke.easyjava.jdbc.util.QingkeConsole;

//主接口
public class BeSuperApplication {

	//饿汉模式-最常用
	private static BeSuperApplication instance;
	
	private BeSuperApplication() {
		
	}
	
	public static synchronized BeSuperApplication getInstance() {
		if(instance == null ){
			instance = new BeSuperApplication();
		}
		return instance;
	}

	private  Player playerProfile;
	
	public static void main(String[] args) {
		
		//start
		QingkeConsole.println("You can use the \"HELP\" for command");
		
		while(true) {
			String cmd = QingkeConsole.askUserInput("cmd");
			CommandCode cc = null;
			try {
				cc = CommandCode.valueOf(cmd.toUpperCase());
			}catch (Exception e) {
				QingkeConsole.println("Please enter a valid command!");
				continue;
			}
			
			Player player = BeSuperApplication.getInstance().getPlayerProfile();
			CommandFactory commandFactory = CommandFactory.buildFactory(player);
			
			Command command = commandFactory.buildCommand(cc);
			if(command != null) {
				command.execute();//执行
			}
		}
	}
	
	public Player getPlayerProfile() {
		return playerProfile;
	}
	
	public void setplayerProfile(Player player ) {
		this.playerProfile = player;
	}
	
}
